<template>
  <div class="param-engine-dashboard">
    <el-button class="back-btn" text circle @click="goBack">
      <el-icon><ArrowLeft /></el-icon>
    </el-button>
    <!-- 页面标题 -->
    <div class="page-header">
      <el-breadcrumb>
        <el-breadcrumb-item :to="{ path: '/dashboard' }">主页</el-breadcrumb-item>
        <el-breadcrumb-item>智能参数引擎</el-breadcrumb-item>
      </el-breadcrumb>
      <h1 class="page-title">
        <el-icon><Setting /></el-icon>
        智能参数引擎
      </h1>
      <p class="page-subtitle">Intelligent Parameter Engine</p>
    </div>

    <!-- 数据概览 -->
    <div class="overview-section">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card class="overview-card">
            <div class="overview-item">
              <div class="overview-icon category">
                <el-icon><Folder /></el-icon>
              </div>
              <div class="overview-content">
                <div class="overview-value">{{ stats.categories }}</div>
                <div class="overview-label">参数分类</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="overview-card">
            <div class="overview-item">
              <div class="overview-icon definition">
                <el-icon><Document /></el-icon>
              </div>
              <div class="overview-content">
                <div class="overview-value">{{ stats.definitions }}</div>
                <div class="overview-label">参数定义</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="overview-card">
            <div class="overview-item">
              <div class="overview-icon rule">
                <el-icon><Star /></el-icon>
              </div>
              <div class="overview-content">
                <div class="overview-value">{{ stats.rules }}</div>
                <div class="overview-label">规则数量</div>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="overview-card">
            <div class="overview-item">
              <div class="overview-icon recommendation">
                <el-icon><Cpu /></el-icon>
              </div>
              <div class="overview-content">
                <div class="overview-value">{{ stats.recommendations }}</div>
                <div class="overview-label">AI推荐</div>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 功能菜单 -->
    <div class="function-menu">
      <h2 class="section-title">功能模块</h2>
      <el-row :gutter="24">
        <!-- 参数分类管理 -->
        <el-col :span="8">
          <el-card class="function-card" shadow="hover" @click="navigateTo('categories')">
            <div class="function-content">
              <div class="function-icon category">
                <el-icon><Folder /></el-icon>
              </div>
              <h3 class="function-title">参数分类管理</h3>
              <p class="function-desc">创建和管理参数分类层级结构，支持多级分类组织</p>
              <div class="function-actions">
                <el-button type="primary" plain size="small">
                  <el-icon><View /></el-icon>
                  查看分类
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>

        <!-- 参数定义管理 -->
        <el-col :span="8">
          <el-card class="function-card" shadow="hover" @click="navigateTo('definitions')">
            <div class="function-content">
              <div class="function-icon definition">
                <el-icon><Document /></el-icon>
              </div>
              <h3 class="function-title">参数定义管理</h3>
              <p class="function-desc">定义参数的基本属性、数据类型、校验规则等</p>
              <div class="function-actions">
                <el-button type="success" plain size="small">
                  <el-icon><Edit /></el-icon>
                  管理定义
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>

        <!-- 参数值管理 -->
        <el-col :span="8">
          <el-card class="function-card" shadow="hover" @click="navigateTo('values')">
            <div class="function-content">
              <div class="function-icon value">
                <el-icon><Edit /></el-icon>
              </div>
              <h3 class="function-title">参数值管理</h3>
              <p class="function-desc">配置不同环境下的参数值，支持版本管理</p>
              <div class="function-actions">
                <el-button type="warning" plain size="small">
                  <el-icon><Setting /></el-icon>
                  配置参数
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>

        <!-- 规则引擎 -->
        <el-col :span="8">
          <el-card class="function-card" shadow="hover" @click="navigateTo('rules')">
            <div class="function-content">
              <div class="function-icon rule">
                <el-icon><Star /></el-icon>
              </div>
              <h3 class="function-title">规则引擎</h3>
              <p class="function-desc">创建和管理参数规则</p>
              <div class="function-actions">
                <el-button type="danger" plain size="small">
                  <el-icon><Lightning /></el-icon>
                  规则管理
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>

        <!-- AI推荐系统 -->
        <el-col :span="8">
          <el-card class="function-card" shadow="hover" @click="navigateTo('ai-recommendations')">
            <div class="function-content">
              <div class="function-icon recommendation">
                <el-icon><Cpu /></el-icon>
              </div>
              <h3 class="function-title">AI推荐系统</h3>
              <p class="function-desc">智能分析参数使用情况，提供优化建议</p>
              <div class="function-actions">
                <el-button type="info" plain size="small">
                  <el-icon><DataAnalysis /></el-icon>
                  智能推荐
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>

        <!-- 系统监控 -->
        <el-col :span="8">
          <el-card class="function-card" shadow="hover" @click="navigateTo('monitoring')">
            <div class="function-content">
              <div class="function-icon monitoring">
                <el-icon><Monitor /></el-icon>
              </div>
              <h3 class="function-title">系统监控</h3>
              <p class="function-desc">监控系统性能、缓存状态、变更历史等</p>
              <div class="function-actions">
                <el-button type="primary" plain size="small">
                  <el-icon><View /></el-icon>
                  查看监控
                </el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 最近活动 -->
    <div class="recent-activity">
      <h2 class="section-title">最近活动</h2>
      <el-card>
        <el-table :data="recentActivities" style="width: 100%">
          <el-table-column prop="time" label="时间" width="180" />
          <el-table-column prop="type" label="类型" width="120">
            <template #default="scope">
              <el-tag :type="getActivityTagType(scope.row.type)">
                {{ scope.row.type }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="description" label="操作描述" />
          <el-table-column prop="operator" label="操作人" width="120" />
          <el-table-column label="操作" width="100">
            <template #default="scope">
              <el-button type="text" size="small" @click="viewActivity(scope.row)">
                查看详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import {
  Setting, Folder, Document, Star, Cpu, Monitor, View, Edit, Lightning,
  DataAnalysis, Plus, ArrowLeft
} from '@element-plus/icons-vue'

const router = useRouter()

// 统计数据
const stats = reactive({
  categories: 12,
  definitions: 156,
  rules: 23,
  recommendations: 8
})

// 最近活动数据
const recentActivities = ref([
  {
    time: '2024-12-19 14:30:25',
    type: '参数更新',
    description: '更新了数据库连接池最大连接数',
    operator: 'admin'
  },
  {
    time: '2024-12-19 13:15:10',
    type: '规则创建',
    description: '创建了新的参数校验规则',
    operator: 'zhangsan'
  },
  {
    time: '2024-12-19 11:45:33',
    type: 'AI推荐',
    description: 'AI系统推荐优化缓存TTL配置',
    operator: 'system'
  },
  {
    time: '2024-12-19 09:20:15',
    type: '分类创建',
    description: '创建了新的参数分类"性能配置"',
    operator: 'lisi'
  }
])

// 页面挂载时加载数据
onMounted(() => {
  loadDashboardData()
})

// 加载仪表板数据
const loadDashboardData = async () => {
  try {
    // TODO: 调用API获取真实数据
    console.log('参数引擎仪表板数据加载完成')
  } catch (error) {
    console.error('加载仪表板数据失败:', error)
    ElMessage.error('数据加载失败')
  }
}

// 导航到指定功能
const navigateTo = (module) => {
  router.push(`/param-engine/${module}`)
}

const goBack = () => {
  router.push('/dashboard')
}

// 获取活动类型标签样式
const getActivityTagType = (type) => {
  const typeMap = {
    '参数更新': 'warning',
    '规则创建': 'success',
    'AI推荐': 'primary',
    '分类创建': 'info'
  }
  return typeMap[type] || 'info'
}

// 查看活动详情
const viewActivity = (activity) => {
  ElMessage.info('活动详情功能开发中')
}
</script>

<style scoped>
.param-engine-dashboard {
  padding: 24px;
  background: #f5f7fa;
  min-height: 100vh;
  position: relative;
}

/* 页面标题 */
.page-header {
  margin-bottom: 32px;
  padding-left: 44px; /* 为左上角返回按钮留出空间，避免遮挡标题 */
  position: relative;
}

.page-title {
  font-size: 32px;
  font-weight: bold;
  color: #303133;
  margin: 16px 0 8px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-subtitle {
  color: #909399;
  font-size: 16px;
  margin: 0;
}

/* 数据概览 */
.overview-section {
  margin-bottom: 32px;
}

.overview-card {
  border-radius: 12px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.overview-item {
  display: flex;
  align-items: center;
  padding: 20px;
}

.overview-icon {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
}

.overview-icon.category { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.overview-icon.definition { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.overview-icon.rule { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
.overview-icon.recommendation { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); }

.overview-icon .el-icon {
  font-size: 28px;
  color: white;
}

.overview-content {
  flex: 1;
}

.overview-value {
  font-size: 28px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 4px;
}

.overview-label {
  font-size: 14px;
  color: #909399;
}

/* 功能菜单 */
.function-menu {
  margin-bottom: 32px;
}

.section-title {
  font-size: 20px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 20px;
}

.function-card {
  border-radius: 16px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  margin-bottom: 24px;
}

.function-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.function-content {
  padding: 30px;
  text-align: center;
}

.function-icon {
  width: 80px;
  height: 80px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.function-icon.category { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.function-icon.definition { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.function-icon.value { background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%); }
.function-icon.rule { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
.function-icon.recommendation { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); }
.function-icon.monitoring { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }

.function-icon .el-icon {
  font-size: 36px;
  color: white;
}

.function-title {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 12px;
}

.function-desc {
  font-size: 14px;
  color: #909399;
  line-height: 1.5;
  margin-bottom: 20px;
  min-height: 42px;
}

.function-actions {
  display: flex;
  justify-content: center;
}

/* 最近活动 */
.recent-activity {
  margin-bottom: 32px;
}

.recent-activity .el-card {
  border-radius: 12px;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .param-engine-dashboard {
    padding: 16px;
  }
  
  .page-title {
    font-size: 24px;
  }
  
  .overview-item {
    padding: 16px;
  }
  
  .overview-icon {
    width: 50px;
    height: 50px;
    margin-right: 16px;
  }
  
  .overview-icon .el-icon {
    font-size: 24px;
  }
  
  .overview-value {
    font-size: 24px;
  }
  
  .function-content {
    padding: 20px;
  }
  
  .function-icon {
    width: 60px;
    height: 60px;
  }
  
  .function-icon .el-icon {
    font-size: 28px;
  }
}
</style>



